package com.example.hellonotes.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;



/**
 *   本类用来处理生成图片的缩略图
 *
 */

public class GetThumbnail {
	
	/**
	 * 处理相机拍摄的图片的缩略图
	 * @param url      所要处理的图片的绝对路径
	 * @param wight    缩略图的宽度
	 * @param height   缩略图的高度
	 * @return
	 */

public Bitmap getImageThumbnail(String url,int wight,int height) {
		
		Bitmap bitmap =null;
		BitmapFactory.Options options = new BitmapFactory.Options();
		options.inJustDecodeBounds=true;
		bitmap = BitmapFactory.decodeFile(url,options);
		options.inJustDecodeBounds=false;
		int beWight = options.outWidth/wight;
		int beHeight = options.outHeight/height;
		int be = 1;
		if (beWight<beHeight) {
			be = beWight;
		} else {
			be = beHeight;
		}
		if (be<=0) {
			be = 1;
		}
		
		options.inSampleSize = be;
		bitmap = BitmapFactory.decodeFile(url, options);
		bitmap = ThumbnailUtils.extractThumbnail(bitmap, wight, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
		
		return bitmap;
		
	}
	
	/**
	 * 处理 视频的缩略图
	 * @param url
	 * @param width
	 * @param height
	 * @param kind
	 * @return
	 */

	public Bitmap getVideoThumbnail(String url,int width,int height,int kind) {
		
		Bitmap bitmap =null;
		bitmap = ThumbnailUtils.createVideoThumbnail(url, kind);
		bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
		return bitmap;
		
	}
}
